/**
 * 
 */
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

/**
 * @author 030998
 *
 */
@Controller
@RequestMapping("/encrypt")
public class RSAEncryptController {
	
	public String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+u/9uyC1Py0Znp3NJzra47bzJ\r\n"
			+ "fxCfCR9zw9mf+PRbyQ7nM4I4j/OKfVZGJaH51B5UZvS+KNRhQEFfGUFPQjRBVLFX\r\n"
			+ "C6MCneVJ0xev7lnzw0ZpbYNbYzB70GxjUQ1NxiMG6julEtqFPqjfRVEGb/A57LY9\r\n"
			+ "RhRH3a/q4w3sqKuVMQIDAQAB";
	
	public String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL67/27ILU/LRmen\r\n"
			+ "c0nOtrjtvMl/EJ8JH3PD2Z/49FvJDuczgjiP84p9VkYlofnUHlRm9L4o1GFAQV8Z\r\n"
			+ "QU9CNEFUsVcLowKd5UnTF6/uWfPDRmltg1tjMHvQbGNRDU3GIwbqO6US2oU+qN9F\r\n"
			+ "UQZv8Dnstj1GFEfdr+rjDeyoq5UxAgMBAAECgYBuC6HQlQYvp6SzYVWPHAkooWHv\r\n"
			+ "D7TTTTwsWq9RMR4rZtGGa52SbNui57XDOys9LTlikRRcMsp2YdBVwgiAZj4nAp1K\r\n"
			+ "F06jTiRd6/sc+Y019BHjt5mtG6QvQ4qSBPwmCMszmDvMRoBnZAMafoyWiUyXuIWo\r\n"
			+ "Y8NmjUa7WbR8EOlKwQJBAPj3ewF/eXpfY90WQM3xVFjltXZTQyx6kJRJhESPZnRc\r\n"
			+ "lJ/Eh8Ph57GNR0jZe0EqVkkLV6eT2VEhM0+84Ax7dlUCQQDEH2H63CidlLYbGZx7\r\n"
			+ "vUFadHlMGwU/cvswC6bpg949pTcKbAjmkWVF+au+kLHlcU6oQxaEuL7QR30odGfP\r\n"
			+ "hmdtAkB6WazShKHfWKeMDBaW3sVz1peB6dM2NZl9tk9RHiPchW7owT1zLz6cy/A/\r\n"
			+ "RdnDoZm71d4i1Y7TxvwfcJOurrHtAkEAqOfGQIB/UkeTFn/WLxNtR3PsS0kyGdTy\r\n"
			+ "1AwU8iOpsTmqz4T/nWM27y75ZKPFMi+FaJBuwltBqqsG9WJbTXUZeQJBAK2uNom5\r\n"
			+ "e099ezU0BrL6eguI1frPhRNToWnMK39SqWq0m9CHx14vhUNFOGMCVIY0iSE7yiCG\r\n"
			+ "zG2r17P1gb9U8v4=";
	
	@RequestMapping("list")
	public String list() {
		return "/modules/encrypt/list";
	}
	
	/**
	 * RSA非对称加密解密
	 * @param data
	 * @return
	 */
	@RequestMapping("/decrypt")
	@ResponseBody
	public String decrypt(String data) {
		RSA rsa = new RSA(privateKey, null);
		
		byte[] bt = rsa.decrypt(data, KeyType.PrivateKey);
		
		String result = StrUtil.str(bt, "utf-8");
		
		System.out.println("result===="+result);
		
		return result;
	}

}
